<template>
  <div class="collect">
    <div style="height: 35px;position: fixed;top: 0;left: 0;right: 0;z-index: 10000">
      <FHeader :username="username"></FHeader>
    </div>
    <div style="position: relative;top: 40px">
      <Order :flowList="shopList" @orderClick="orderClick" :collectType="1"></Order>
    </div>
  </div>
</template>

<script>
import FHeader from '@/components/FHeader';
import Order from '@/components/Order';
export default {
  components:{
    FHeader,
    Order
  },
  name: 'collect',
  data(){
    return {
      username: '',
      shopList: []
    }
  },
  created() {
    this.getUser()
    this.getCollect()
  },
  methods:{
    getUser() {
      let user = JSON.parse(window.sessionStorage.getItem('user') || null);
      if (user) {
        this.username = user.username;
        this.userId = user.id;
      }
    },
    async getCollect(){
      let that = this
      let user = JSON.parse(window.sessionStorage.getItem('user') || null);
      let dataId = {
        userId: user.id,
        orderType: 0,
        sellerId: ''
      }
      const { data: res } = await this.$http.post('order/getAllOrder', dataId);
      if (res.flag == "200"){
        let serve = res.orderList
        that.shopList = []
        serve.forEach((item, index) => {
          if (item.shop.shopUrl.indexOf("<<tupian>>") > 0) {
            item.shop.shopUrl = item.shop.shopUrl.split("<<tupian>>")[0]
            // console.log(index)
          }
          item.creatTime = that.formatDateTime(item.creatTime)
          item.updateTime = that.formatDateTime(item.updateTime)
          that.shopList.push(item)
        })
      }
    },
    async orderClick(option){
      let that = this
      let dataId = {
        id: option.id,
        orderType: option.index,
        shopId: option.shopId
      }
      const { data: res } = await this.$http.post('order/updateOrderType', dataId);
      if (res.flag == "200"){
        that.getCollect();
      }
    },
  }
};
</script>

<style lang="less" scoped>

</style>
